package com.example.jetpack.a_viewbinding

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.jetpack.databinding.FragmentAFirstBinding

class FirstFragment : Fragment() {

    /**
     * ViewBinding
     */
    private var _binding: FragmentAFirstBinding? = null
    private val binding get() = _binding!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        _binding = FragmentAFirstBinding.inflate(layoutInflater)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val view = binding.root
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val textview = binding.textView

        /**
         * 获取activity传递过来的参数
         */
        textview.text = arguments?.getString("key") ?: "there isn't initial data"
    }


    override fun onDestroyView() {
        super.onDestroyView()

        /**
         *  clear all references to the binding class instance
         */
        _binding = null
    }
}